<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${packageName}.mapper.${mapperName}">

    <resultMap id="BaseResultMap" type="${packageName}.model.${modelName}">
        <#list primaryKeys as column>
        <id column="${column.columnName}" property="${column.propertyName?uncap_first}" jdbcType="<#if column.type='Integer'>INTEGER<#elseif column.type='Date'>TIMESTAMP<#elseif column.type='String'>VARCHAR<#else>${column.type}</#if>" />
        </#list>
        <#list columns as column>
        <result column="${column.columnName}" property="${column.propertyName?uncap_first}" jdbcType="<#if column.type='Integer'>INTEGER<#elseif column.type='Date'>TIMESTAMP<#elseif column.type='String'>VARCHAR<#else>${column.type}</#if>" />
        </#list>
    </resultMap>

    <select id="getAll${modelName}s" resultMap="BaseResultMap">
        select * from ${tableName};
    </select>

    <select id="get${modelName}ById" resultMap="BaseResultMap">
        select * from ${tableName}
        <where>
                <#list primaryKeys as column>
            ${column.columnName} = <#noparse>#{</#noparse>${column.propertyName?uncap_first}<#noparse>}</#noparse><#if column_has_next> and </#if>
                </#list>
        </where>

    </select>

    <update id="update${modelName}ById">
        update ${tableName}
        <set>
            <#list columns as column>
            ${column.columnName} = <#noparse>#{</#noparse>${column.propertyName?uncap_first}<#noparse>}</#noparse><#if column_has_next>, </#if>
            </#list>
        </set>
        <where>
            <#list primaryKeys as column>
            ${column.columnName} = <#noparse>#{</#noparse>${column.propertyName?uncap_first}<#noparse>}</#noparse><#if column_has_next> and </#if>
            </#list>
        </where>
    </update>

    <delete id="delete${modelName}ById">
        delete from ${tableName}
        <where>
            <#list primaryKeys as column>
            ${column.columnName} = <#noparse>#{</#noparse>${column.propertyName?uncap_first}<#noparse>}</#noparse><#if column_has_next> and </#if>
            </#list>
        </where>
    </delete>

    <delete id="deleteAll${modelName}s">
        delete from ${tableName}
    </delete>
    
    <insert id="add${modelName}">
        insert into ${tableName}(<#list columns as column>${column.columnName}<#if column_has_next>, </#if></#list>) values(<#list columns as column><#noparse>#{</#noparse>${column.propertyName?uncap_first}<#noparse>}</#noparse><#if column_has_next>, </#if></#list>)
    </insert>
</mapper>